home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / batch / batcher9 / fastbat.txt < prev    next >
Encoding:
Text File  |  1985-06-18  |  4.6 KB  |  108 lines

  1.                         SPEEDING UP BATCH FILES
  2.  
  3. Batch files make life a lot easier, but they are very slow.  Even when
  4. using batch files in RAM disks, execution time is quite noticeable.  It
  5. reminds me of the time when a batch file meant a batch of cards.  The
  6. techniques described here reduce the time required to execute batch
  7. file by as much as an order of magnitude.
  8.  
  9. Execution time is closely related to the number of lines rather than
  10. the number of characters.  To save time, put as many commands on one
  11. line as possible.  Some ways to do this:
  12.  
  13. 1.  Instead of using a lot of lines for remarks, put what you have to
  14.     say in a file and issue the batch command TYPE FILE.  TYPEing a file
  15.     takes less than 30% as long as echoing the same information from a
  16.     batch file.
  17.  
  18. 2.  Instead of using a lot of lines to issue commands, put all the
  19.     commands in a FOR subcommand.  For instance, your autoexec.bat file
  20.     might start out:
  21.  
  22.                    fastdisk
  23.                    parint
  24.                    scrnsave
  25.                    spool 7
  26.                    sk
  27.                    c:
  28.  
  29.     Instead, just say:
  30.  
  31.         for %%f in (fastdisk parint scrnsave spool:7 sk c:) do %%f
  32.  
  33.     This reduces six lines to one.  In Dos 2.1, but not in 3.0, you can
  34.     eliminate spaces and slightly decrease execution time like this:
  35.  
  36.         for %%fin(fastdisk parint scrnsave spool:7 sk c:)do%%f
  37.  
  38.     Note the colon between spool and 7.  You can't have any spaces within
  39.     the parentheses except to denote the beginning of a new command.
  40.  
  41. 3.  When copying files use the FOR subcommand and wild cards like this:
  42.  
  43.         for %%fin(print v sp)docopy a:%%f???.*
  44.  
  45.     The FOR subcommand does not support wild cards within the parentheses.
  46.  
  47.     How much time the FOR subcommand will save, if any, depends on how the
  48.     disk buffers are used while the subcommand is being executed.  DOS
  49.     remembers the entire subcommand.  It doesn't have to go back to disk to
  50.     read more of the subcommand as it goes along.  But DOS doesn't remember
  51.     the contents of the batch file unless it is held in disk buffers.
  52.     Whether or not the disk buffers keep the contents of the batch file
  53.     depends on what you're doing between batch commands.
  54.  
  55. 4.  The IF subcommand supports conditional commands and the FOR
  56.     subcommand.  For instance, you might want to see if a file exists 
  57.     and, if it does, to run several programs and then to return to the 
  58.     menu; or, if it doesn't to display a message and return to the menu.
  59.     A batch file for this task might look like this:
  60.  
  61.          If exist myufile goto programs
  62.          echo File does not exist.  Try again.
  63.          d:menu
  64.          :programs
  65.          myprog.ram
  66.          second.prg
  67.          third
  68.          d:menu
  69.  
  70.     But it will run faster like this:
  71.  
  72.     If exist myfile for %%fin(myprog.ram second.prg third d:menu)do%%f
  73.     for %%fin(echo d:menu)do%%f File does not exist.  Try again,
  74.  
  75. 5.  When a command processor or another batch file is invoked, batch
  76.     processing for the first batch is terminated.  You don't need to exit
  77.     the batch file.  For example, in the batch file fragment below, the
  78.     command GOTO GETOUT (and probably the label :GETOUT) is unnecessary and
  79.     will increase execution time in some cases:
  80.             ..
  81.          command c:
  82.          goto to getout
  83.             ..
  84.             ..
  85.          :getout.
  86.  
  87. 6.  A fast way to get out of the middle of a batch file is to issue a
  88.     command for another batch file, say a file called exit.  EXIT can contain
  89.     only the command REM or just a dot or better yet nothing.  A file that
  90.     contains nothing doesn't take up any disk space.  You can create such a
  91.     file with another batch file, say autoexec.bat, by inserting this command
  92.  
  93.     for %%fin(echo rem)do%%f >d:exit.bat
  94.  
  95.     The rem part of the command can be any command that doesn't look for
  96.     parameters on the command line, e.g. cls or pause or sk.
  97.  
  98. 7.  Of course, running batch files from a RAM disk is a big help.  It's some-
  99.     times worth transferring control to a batch file that has been copied 
  100.     onto your RAM disk.  The time required for handling the batch operations 
  101.     in a RAM disk is less than a third of that required for a floppy.
  102.  
  103. 8.  Putting an end-of-file marker (ASCII 26 or Control Z) on the same line 
  104.     and immediately after the last command, will prevent annoying multiple 
  105.     prompts at the end of batch processing.
  106.  
  107. Bob Unferth                                           Wilmette, IL
  108.